/*
 * @Author: your name
 * @Date: 2020-11-05 18:21:31
 * @LastEditTime: 2020-12-17 17:13:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-element-admine:\hjimi\人脸\html\face-recognition\src\utils\auth.js
 */
import cookies from 'js-cookie'
import router from "../router";
import { Message } from 'element-ui'
// import store from '@/store'

// token操作
export function getToken() {
  return cookies.get('token')
}

export function setToken(tokenValue) {
  let millisecond = new Date().getTime(),
  expiresTime = new Date(millisecond + 60 * 1000 * 120); //2h后过期
  return cookies.set('token', tokenValue, {expires: expiresTime})
}

export function removeToken() {
  cookies.remove('token')
  Message({
    message: "登录状态已过期，请重新登录",
    type: "warning",
    duration: 5 * 1000
  });
  router.push({path:'/'})  //token过期
}

export function removeCookie(x){
  return cookies.remove(x)
}

// 用户信息操作
export function getUser() {
  if(cookies.get('User')) {
    return JSON.parse(cookies.get('User'))
  }
}



